package com.ms.es.result.impl;

import com.ms.common.exception.ESQueryException;
import com.ms.common.utils.GsonUtil;
import com.ms.es.result.EsSearchByIdResult;
import com.ms.es.sql.SqlDesc;

public class EsSearchByIdResultHandler extends BaseResultHandler {

    @Override
    public Object handler(String result, SqlDesc sqlDesc) {
        try {
            EsSearchByIdResult queryResult = GsonUtil.str2Object(result, EsSearchByIdResult.class);
            if (queryResult.isFound()) {
                return GsonUtil.obj2Object(queryResult.get_source(), sqlDesc.getResultType());
            } else {
                return null;
            }
        } catch (Exception e) {
            throw new ESQueryException(result, e);
        }
    }

}
